package networkListener;

/**
 * @author re0hg
 * @version 1.0
 * @date 2025/3/28
 */

import org.pcap4j.core.*;

public class Main {
    public static void main(String[] args) {
        try {
            // 打印所有可用的网络接口
            System.out.println("Listing all network interfaces:");
            Pcaps.findAllDevs().forEach(dev -> {
                System.out.println("Device Name: " + dev.getName());
                System.out.println("Device Description: " + dev.getDescription());
            });

            PcapNetworkInterface device = Pcaps.findAllDevs().stream()
                    .filter(dev -> !dev.getName().equals("\\Device\\NPF_Loopback"))  // 排除回环接口
                    .filter(dev -> dev.getDescription().contains("Wi-Fi") || dev.getDescription().contains("WLAN"))  // 选择 WLAN 或 Wi-Fi 接口
                    .findFirst()
                    .orElseThrow(() -> new RuntimeException("Network interface not found"));
            System.out.println("Using network interface: " + device.getDescription());
            // 初始化网络监听器
            NetworkListener listener = new NetworkListener(device);
            listener.startListening();

        } catch (PcapNativeException e) {
            e.printStackTrace();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }
}



